package com.kitty.game.fight.util;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.mina.message.Message;
import com.kitty.mina.message.MessagePusher;

import java.util.Collections;
import java.util.List;

public class FightMessageUtil {

    /**
     * 发送战场消息 列表
     *
     * @param fight
     * @param messages
     */
    public static void sendFightPackage(Fight fight, List<Message> messages) {
        for (FightObject fightObject : fight.getListA()) {
            if (fightObject.isPlayer()) {
                for (Message message : messages) {
                    MessagePusher.pushMessage(fightObject.getRole(), message);
                }
            }
        }
        /**是人物对战就给B方发*/
        if (fight.isPkFight()) {
            for (FightObject fightObject : fight.getListB()) {
                if (fightObject.isPlayer()) {
                    for (Message message : messages) {
                        MessagePusher.pushMessage(fightObject.getRole(), message);
                    }
                }
            }
        }
    }

    /**
     * 发送战场Message 单个
     */
    public static void sendFightPackage(Fight fight, Message message) {
        if (fight == null || message == null) {
            return;
        }
        sendFightPackage(fight, Collections.singletonList(message));
    }

    /**
     * @param fight
     * @param message
     * @param isA     true A方发送 false B方发送
     */
    public static void sendFightPackage(Fight fight, Message message, boolean isA) {
        if (fight == null || message == null) {
            return;
        }
        sendFightPackage(fight, Collections.singletonList(message), isA);
    }

    public static void sendFightPackage(Fight fight, List<Message> messages, boolean isA) {
        List<FightObject> targets = isA ? fight.getListA() : fight.getListB();
        for (FightObject fightObject : targets) {
            if (fightObject.isPlayer()) {
                for (Message message : messages) {
                    MessagePusher.pushMessage(fightObject.getRole(), message);
                }
            }
        }
    }

    public static void sendFightPackage(Message message, List<FightObject> targets) {
        for (FightObject fightObject : targets) {
            if (fightObject.isPlayer()) {
                MessagePusher.pushMessage(fightObject.getRole(), message);
            }
        }
    }
}
